package com.example.multity

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity

const val FIRST_MSG="FIRST_MSG"
const val SECOND_MSG="SECOND_MSG"
@Suppress("DEPRECATTON")
class MainActivity : ComponentActivity() {
    private lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val first=findViewById<Button>(R.id.first)
        val editText=findViewById<EditText>(R.id.editText)


        val second=findViewById<Button>(R.id.second)
        textView=findViewById(R.id.textView)

        val Third=findViewById<Button>(R.id.third)
        val fourth=findViewById<Button>(R.id.fourth)


        first.setOnClickListener {

            val intent= Intent(this, SecondActivity::class.java)
            intent.putExtra(FIRST_MSG,editText.text.toString())
            startActivity(intent)
        }
        second.setOnClickListener {
            val intent= Intent(this, ThirdActivity::class.java)
            startActivityForResult(intent,0)
        }
        Third.setOnClickListener {
            val intent= Intent(this, forthActivity::class.java)
            startActivity(intent)
        }
        fourth.setOnClickListener {
            val intent=Intent(this, FifthActivity::class.java)
            startActivity(intent)
        }

    }

    override fun onActivityResult(
        requestCode: Int,
        resultCode: Int,
        data: Intent?
    ) {
        super.onActivityResult(requestCode, resultCode, data)
        if(requestCode==0){
            if(resultCode==1){
                textView.text=data?.getStringExtra(SECOND_MSG)
            }
        }
    }
}

